
package com.treeman.navi.route;

public class Distance
{

    public final static String TAG = "Distance";

    private int distance = 0;

    private Boolean started = false;


    public void start()
    {
	this.started = true;
    }

    public void stop()
    {
	this.started = false;
    }

    public void addDistance(int distance)
    {
	if (isStarted()) this.distance += distance;
    }

    public void detachDistance(int distance) throws NegativeDistanceException
    {
	if (isStarted())
	{
	    int dist = this.distance;
	    if (dist - distance > 0)
	    {
		this.distance -= distance;
	    }
	    else
		throw new NegativeDistanceException(this);
	}
    }

    public void setDistance(int distance)
    {
	this.distance = distance;
    }

    public Boolean isStarted()
    {
	return started;
    }

    public String getDistanceString()
    {
	int dist = distance;
	String unit = " m";

	if (dist >= 1000)
	{
	    dist /= 1000;
	    unit = " km";
	}
	return dist + unit;
    }

    public int getDistance()
    {
	return distance;
    }

}
